home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_actor_aitokarev.cog < prev    next >
Text File  |  1999-11-15  |  7KB  |  316 lines

  1. # ===================================================================
  2. # Jones 3D Cog Script
  3. #
  4. # actor_AITokarev.cog
  5. #
  6. # [RandyT]
  7. #
  8. # Actor script for any AI with a Tokarev pistol.
  9. #
  10. # (C) 1998 LucasArts Entertainment Company LLC. All Rights Reserved
  11. # ===================================================================
  12.  
  13. symbols
  14.  
  15. message        created
  16. message        damaged
  17. message        killed
  18. message        timer
  19.  
  20. # ************************** TEMPLATES *************************
  21. template    tplGun=tokarev                local
  22. template    tplPoisonKit=poisonkit        local
  23. template    tplHealthKit=hlthsml        local
  24. template    tplFire=+bazooka_exp_fire    local
  25. template    tplSmoke=+bazooka_exp_smoke    local
  26. template    tplSparks=lavadeathsparks    local
  27.  
  28. # ************************** WEAPON HANDLERS *******************
  29. int            weaponNum=20                local
  30. int            damageType                    local
  31.  
  32. # ************************** AI VARS ***************************
  33. ai            fists=com_fists.ai            local
  34.  
  35. int            TIMER_ID_WAKEUP_NORMAL=0    local
  36. int            TIMER_ID_WAKEUP_AND_DIE=1    local
  37.  
  38. # ************************** MISC LOCAL VARS *******************
  39. thing        bandito                        local
  40. thing        indy                        local
  41. thing        powerup                        local
  42.  
  43. int            timerID                        local 
  44. int            index                        local
  45. int            numSmallKits                local
  46. int            numBigKits                    local
  47. int            kitTotal                    local
  48. int            bItemCreated                local
  49.  
  50. flex        indyHealth                    local
  51. flex        kitChance                    local
  52.  
  53. vector        dir                            local
  54. vector        randVec                        local
  55.  
  56. # ************************** SUBROUTINES ***********************
  57. flex        Disarm                        local
  58. flex        WhipIt                        local
  59. flex        PushIt                        local
  60. flex        GetKitChance                local
  61. flex        CheckHealthBins                local
  62.  
  63. end
  64.  
  65. # ===================================================================
  66. code
  67.  
  68. # -------------------------------------------------------------------
  69. created:
  70.  
  71.     bandito = GetSenderRef();
  72.     indy = GetLocalPlayerThing();
  73.  
  74.     SetWeaponModel(bandito, weaponNum);
  75.     SelectWeapon(bandito, weaponNum);
  76.  
  77.     AIEnableInstinct(bandito, "circlestrafe", 0);
  78.     AIEnableInstinct(bandito, "roam", 0);
  79.  
  80.     return;
  81.  
  82. # -------------------------------------------------------------------
  83. damaged:
  84.  
  85.     bandito = GetSenderRef();
  86.     damageType = GetParam(1);
  87.  
  88.     # Been whipped?
  89.     if (damageType == 0x10)
  90.     {
  91.         call Disarm;
  92.     }
  93.  
  94.     # Been punched?
  95.     else if (damageType == 0x08)
  96.     {
  97.         if ((GetParam(0) < GetThingHealth(bandito)) && (GetParam(0) * 2) > GetThingHealth(bandito))
  98.         {
  99.             # Make sure thing's not already disabled
  100.             if (BITTEST(GetActorFlags(bandito), 0x40008)) return;
  101.  
  102.             call Disarm;
  103.  
  104.             # Play dead
  105.             AIKnockOut(bandito, RandBetween(10, 30), TIMER_ID_WAKEUP_NORMAL);
  106.         }
  107.     }
  108.  
  109.     # Jeep or MineCar hit us
  110.     else if (damageType == 0x02000000)
  111.     {
  112.         # If invulnerable or immobile, ignore -- avoids multiple collision problem
  113.         if (BITTEST(GetActorFlags(bandito), 0x40008))
  114.         { 
  115.             ReturnEx(0);
  116.             return;
  117.         }
  118.         else if (GetParam(0) >= GetThingHealth(bandito))
  119.         {
  120.             call Disarm;
  121.  
  122.             # Pause long enough to land
  123.             AIRunOver(bandito, RandBetween(5, 6), TIMER_ID_WAKEUP_AND_DIE);
  124.             ReturnEx(0);
  125.             return;
  126.         }
  127.     }
  128.  
  129.     return;
  130.  
  131. # -------------------------------------------------------------------
  132. killed:
  133.  
  134.     bandito = GetSenderRef();
  135.     damageType = GetParam(1);
  136.  
  137.     # Killed by lava?
  138.     if (damageType == 0x200)
  139.     {
  140.         Sleep(0.1);
  141.         CreateThing(tplFire, bandito);
  142.         Sleep(0.3);
  143.         CreateThing(tplSmoke, bandito);
  144.         SetThingFlags(bandito, 0x80000);
  145.  
  146.         for (index = 0; index < 10; index = index + 1)
  147.         {
  148.             CreateThing(tplSparks, bandito);
  149.             Sleep(0.03);
  150.         }
  151.     }
  152.     else
  153.     {
  154.         call Disarm;
  155.     }
  156.  
  157.     return;
  158.  
  159. # -------------------------------------------------------------------
  160. timer:
  161.  
  162.     bandito = GetParam(0);
  163.     timerID = GetSenderId();
  164.  
  165.     if (timerID == TIMER_ID_WAKEUP_NORMAL)
  166.     {
  167.         # Knocked out but not killed
  168.         AIKnockOut(bandito, 0, TIMER_ID_WAKEUP_NORMAL);
  169.         SetHealth(bandito, 100.0);
  170.     }
  171.     else if (timerID == TIMER_ID_WAKEUP_AND_DIE)
  172.     {
  173.         # Make sure not invulnerable
  174.         ClearActorFlags(bandito, 0x8);
  175.         # Using scrape damage to avoid infinite loop
  176.         DamageThing(bandito, GetThingMaxHealth(bandito), 0x1000000, GetLocalPlayerThing());
  177.     }
  178.  
  179.     return;
  180.  
  181. # ===================================================================
  182. #    Subroutines
  183. # ===================================================================
  184.  
  185. Disarm: # Note: damageType must already be set!
  186.  
  187.     bItemCreated = 0;
  188.  
  189.     if (AIGetArmedMode(bandito) != 0)
  190.     {
  191.         # Swap the gun back out
  192.         ResetWeaponModel(bandito);
  193.  
  194.         # A whipped gun behaves a bit differently...
  195.         if (damageType == 0x10)
  196.         {
  197.             powerup = CreateThing(tplGun, bandito);
  198.             call WhipIt;
  199.             return;
  200.         }
  201.         # We're roadkill...
  202.         else if (damageType == 0x02000000)
  203.         {
  204.             powerup = CreateThing(tplGun, bandito);
  205.             call PushIt;
  206.             return;
  207.         }
  208.  
  209.         # Check our chances of dropping a health kit
  210.         call GetKitChance;
  211.  
  212.         # Create a new weapon, or maybe a health or snake bite kit
  213.         if (Rand() > kitChance)
  214.         {
  215.             powerup = CreateThing(tplGun, bandito);
  216.             call PushIt;
  217.         }
  218.         else
  219.         {
  220.             # Is Indy poisoned?
  221.             if (BitTest(GetActorFlags(indy), 0x2000))
  222.             {
  223.                 # Have any poison kits?
  224.                 if (GetInv(indy, 46) < 1)
  225.                 {
  226.                     if (Rand() < 0.25)
  227.                     {
  228.                         powerup = CreateThing(tplPoisonKit, bandito);
  229.                         call PushIt;
  230.                         return;
  231.                     }
  232.                 }
  233.             }
  234.             
  235.             # If we haven't created anything yet...
  236.             if (!bItemCreated)
  237.             {
  238.                 # See what Indy's already holding
  239.                 call CheckHealthBins;
  240.  
  241.                 if (kitTotal <= 30)
  242.                     powerup = CreateThing(tplHealthKit, bandito);
  243.                 else
  244.                     powerup = CreateThing(tplGun, bandito);
  245.                 
  246.                 call PushIt;
  247.             }
  248.         }
  249.     }
  250.  
  251.     return;
  252.  
  253. # -------------------------------------------------------------------
  254.  
  255. WhipIt: # Note: powerup must already be initialized!
  256.  
  257.     # Push powerup towards Indy...
  258.     dir = VectorAdd(GetThingPos(GetLocalPlayerThing()), '0.0 0.0 0.75');
  259.     dir = VectorScale(VectorSub(dir, GetThingPos(powerup)), 4.75);
  260.     ApplyForce(powerup, dir);
  261.  
  262.     # Time for fists...
  263.     AISetClass(bandito, fists);
  264.     SelectWeapon(bandito, 19);
  265.  
  266.     return;
  267.  
  268. # -------------------------------------------------------------------
  269.  
  270. PushIt: # Note: powerup must already be initialized!
  271.  
  272.     # Push powerup away a little...
  273.     dir = VectorTransformToOrient(bandito, '-0.17 0.0 0.0');
  274.     randVec = VectorSet(0, Rand() * 360, 0);
  275.     dir = VectorRotate(dir, randVec);
  276.     SetThingVel(powerup, dir);
  277.  
  278.     # Time for fists...
  279.     AISetClass(bandito, fists);
  280.     SelectWeapon(bandito, 19);
  281.     bItemCreated = 1;
  282.  
  283.     return;
  284.  
  285. # -------------------------------------------------------------------
  286.  
  287. GetKitChance:
  288.  
  289.     indyHealth = GetThingHealth(indy);
  290.     if (indyHealth >= 750.0) kitChance = 0.05; 
  291.     else if (indyHealth >= 500.0) kitChance = 0.1;
  292.     else if (indyHealth >= 250.0) kitChance = 0.15;
  293.     else kitChance = 0.25;
  294.  
  295.     return;
  296.  
  297. # -------------------------------------------------------------------
  298.  
  299. CheckHealthBins:
  300.  
  301.     kitTotal = 0;
  302.  
  303.     numSmallKits = GetInv(indy, 39);                # Small herbs
  304.     numSmallKits = numSmallKits + GetInv(indy, 49);    # Small health
  305.  
  306.     numBigKits = GetInv(indy, 38);                    # Big herbs
  307.     numBigKits = numBigKits + GetInv(indy, 48);        # Big health
  308.  
  309.     numSmallKits = numSmallKits * 5;
  310.     numBigKits = numBigKits * 10;
  311.  
  312.     kitTotal = numSmallKits + numBigKits;
  313.  
  314.     return;
  315.  
  316. end